import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:何人亮
 * Date:2024-07-31
 * 10:17
 */
public class Test {
    public static void main(String[] args) {

    }

    public boolean isValid(String s) {

            if(s.length()==1){
                return false;
            }
            Stack<Character> stack=new Stack<>();
            for (int i = 0; i < s.length(); i++) {
                char ch=s.charAt(i);
                if(ch=='('||ch=='{'||ch=='['){
                    stack.push(ch);
                }else {

                    if(stack.isEmpty()){
                        return false;
                    }
                    char ch1=stack.peek();
                    if(ch1=='('&&ch==')'||ch1=='{'&&ch=='}'||ch1=='['&&ch==']'){
                        stack.pop();
                    }else{
                        return false;
                    }
                }
            }
            if(!stack.isEmpty()){
                return false;
            }
            return true;
        }
}
